package com.tronsis.distribution.activity.me.points;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.tronsis.distribution.R;
import com.tronsis.distribution.fragment.point.PointProcessingFragment;
import com.tronsis.library.activity.ToolBarBaseActivity;
import com.tronsis.library.adapter.SimpleViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class PointProcessingActivity extends ToolBarBaseActivity {
    @BindView(R.id.tab_layout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.viewpager)
    ViewPager mViewPager;

    private List<Fragment> mPageList = new ArrayList<>();
    private int mIndex = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_point_processing);
        setTitle(true, getString(R.string.point_withdraw_processing));

        mPageList.add(getFragment("PAY"));
        mPageList.add(getFragment("CONFIRM"));
        mPageList.add(getFragment("REPORT"));
        mPageList.add(getFragment("FINISH"));

        SimpleViewPagerAdapter adapter = new SimpleViewPagerAdapter(getSupportFragmentManager(), mPageList);
        mViewPager.setAdapter(adapter);

        final String[] mTitles = {"待付款", "待确定", "申诉中", "已完成"};

        mTabLayout.setViewPager(mViewPager, mTitles);

        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                mIndex = position;
            }

            @Override
            public void onTabReselect(int position) {

            }
        });

        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                mIndex = i;
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mPageList.get(0).onActivityResult(requestCode, resultCode, data);
    }

    private PointProcessingFragment getFragment(String state) {
        PointProcessingFragment fm = new PointProcessingFragment();
        Bundle bundle = new Bundle();
        bundle.putString("state", state);
        fm.setArguments(bundle);
        return fm;
    }

}


